#include "chatroomview.h"
#include "ui_chatroomview.h"
#include "common.h"
#include <QMenu>

ChatroomView::ChatroomView(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ChatroomView)
{
    ui->setupUi(this);

    QMenu* optionsMenu = new QMenu(this);
    connect(optionsMenu->addAction(tr("Previous Room")), SIGNAL(triggered()), SLOT(onPrevRoom()));
    connect(optionsMenu->addAction(tr("Next Room")), SIGNAL(triggered()), SLOT(onNextRoom()));
    connect(optionsMenu->addAction(tr("Show Room List")), SIGNAL(triggered()), SLOT(onShowRoomList()));
    connect(optionsMenu->addAction(tr("Show User List")), SIGNAL(triggered()), SLOT(onShowUserList()));
    connect(optionsMenu->addAction(tr("Options")), SIGNAL(triggered()), SLOT(onOptions()));

#ifdef Q_WS_S60

    setContextMenuPolicy(Qt::ActionsContextMenu);

    QAction* optionsMenuAction = new QAction(tr("Options"), this);
    optionsMenuAction->setSoftKeyRole(QAction::PositiveSoftKey);
    addAction(optionsMenuAction);

    QAction* hideMenuAction = new QAction(tr("Hide"), this);
    hideMenuAction->setSoftKeyRole(QAction::NegativeSoftKey);
    addAction(hideMenuAction);

    connect(hideMenuAction, SIGNAL(triggered()), g_application, SLOT(quit()));

    optionsMenuAction->setMenu(optionsMenu);
#else
    QAction* actions = new QAction(tr("Menu"), this);
    actions->setMenu(optionsMenu);
    addAction(actions);
#endif
}

ChatroomView::~ChatroomView()
{
    delete ui;
}

const QString& ChatroomView::name()
{
    return iRoomName;
}

void ChatroomView::setName(const QString &aRoomName)
{
    iRoomName = aRoomName;
    ui->channelTitle->setText(aRoomName);
    appendLine(tr("Channel name set to %1").arg(aRoomName));
}

void ChatroomView::appendLine(const QString &aLine)
{
    ui->inputBox->insert(aLine);
    ui->inputBox->insert("\r\n");
}

void ChatroomView::onMessage(QString aFrom, int aTime, QString aText)
{
    appendLine(tr("[%1] <%2> %3").arg(aFrom, FormatTime(aTime), aText));
}

void ChatroomView::onPrevRoom()
{
    //
}

void ChatroomView::onNextRoom()
{
    //
}

void ChatroomView::onShowRoomList()
{
    //
}

void ChatroomView::onShowUserList()
{
    //
}

void ChatroomView::onOptions()
{
    //
}
